from peewee import *
from playhouse.pool import PooledMySQLDatabase

db = PooledMySQLDatabase('test',
                         **{'charset': 'utf8', 'sql_mode': 'PIPES_AS_CONCAT', 'use_unicode': True, 'user': 'root',
                            'password': 'root'},
                         max_connections=32,  # 最大连接数量
                         stale_timeout=300,  # 5 分钟
                         )


class UnknownField(object):
    def __init__(self, *_, **__): pass


class BaseModel(Model):
    class Meta:
        database = db


class User(BaseModel):
    age = IntegerField(null=True)
    birthday = DateTimeField(null=True)
    name = CharField(null=True)

    class Meta:
        table_name = 'user'


# 查询结果排序
for user in User.select().order_by(User.age):
    print(user.name, user.age, user.birthday)
